package com.moorror.codegenvel.db.sqlite;

import com.google.common.collect.Maps;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.compress.utils.Lists;

import java.util.List;
import java.util.Map;

/**
 * @Author jiyanghuang
 * @Date 2024/5/25 15:55
 */
public enum SqliteUpdateEnum {
    ;
    private String tableName;
    private String columnName;
    private String addColumnSql;

    SqliteUpdateEnum(String tableName, String columnName, String addColumnSql) {
        this.tableName = tableName;
        this.columnName = columnName;
        this.addColumnSql = addColumnSql;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getAddColumnSql() {
        return addColumnSql;
    }

    public void setAddColumnSql(String addColumnSql) {
        this.addColumnSql = addColumnSql;
    }

    public static Map<String, List<SqliteUpdateEnum>> tableNameUpdataMap() {
        Map<String, List<SqliteUpdateEnum>> tableNameUpdataMap = Maps.newTreeMap();
        for (SqliteUpdateEnum sqliteUpdateEnum : values()) {
            List<SqliteUpdateEnum> updateSql = tableNameUpdataMap.get(sqliteUpdateEnum.getTableName());
            if (CollectionUtils.isEmpty(updateSql)) {
                updateSql = Lists.newArrayList();
                tableNameUpdataMap.put(sqliteUpdateEnum.getTableName(), updateSql);
            }
            updateSql.add(sqliteUpdateEnum);
        }
        return tableNameUpdataMap;
    }
}

